package org.jeecg.modules.wangyue.controller.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.wangyue.constant.DelFlagConstant;
import org.jeecg.modules.wangyue.entity.ContractTemplate;
import org.jeecg.modules.wangyue.service.IContractTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Arrays;

/**
* @Description: 协议配置
* @Author: jeecg-boot
* @Date:   2023-06-30
* @Version: V1.0
*/
@Slf4j
@Api(tags="协议配置")
@RestController
@RequestMapping("/wangyue/sys/contractTemplate")
@Validated
public class ContractTemplateManageController extends JeecgController<ContractTemplate, IContractTemplateService> {
   @Autowired
   private IContractTemplateService contractTemplateService;


    /**
     * 协议配置-查询协议
     *
     * @param id  唯一id
     * @return
     */
   @AutoLog(value = "协议配置-查询协议")
   @ApiOperation(value="协议配置-查询协议", notes="协议配置-查询协议")
   @GetMapping(value = "/queryContractById")
   public Result<?> queryContractById(@RequestParam(name="id", required = true) @NotBlank(message = "id不能为空") String id) {
       QueryWrapper<ContractTemplate> queryWrapper = new QueryWrapper<>();
       queryWrapper.eq("id", id);
       queryWrapper.eq("del_flag", DelFlagConstant.normal);
       return Result.OK("查询成功", contractTemplateService.getOne(queryWrapper));
   }

   /**
    * 协议配置-保存
    *
    * @param contractTemplate
    * @return
    */
   @AutoLog(value = "合同模版表-保存")
   @ApiOperation(value="合同模版表-保存", notes="合同模版表-保存")
   @PostMapping(value = "/save")
   public Result<?> save(@Valid @RequestBody ContractTemplate contractTemplate) {
       if(contractTemplateService.saveOrUpdate(contractTemplate)){
           return Result.OK("保存成功！");
       }else {
           return Result.error("保存失败！");
       }
   }




}
